<template>
	<view class="app">
		<view class="panel">
			<view class="flex-col setpidpage">
				<view class="flex justify-between inputitem">
					<view>上级ID</view>
					<view><input v-model="pid" placeholder="请输入组长ID" /></view>
				</view>
				<view class="flex justify-between inputitem">
					<view>下级ID</view>
					<view>
						<input v-model="uid" placeholder="请输入下线ID列表" />
						<text class="tips">
							使用英文字逗号分割，如：111,222,333
						</text>
					</view>
				</view>
				<view class="flex justify-center items-center btn-save">
					<button @tap.stop="save">保存设置</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	var that,App=getApp(),Comm=getApp().comm;
	export default {
		data() {
			return {
				pid:'',
				uid:''
			}
		},
		onLoad() {
			that=this;
		},
		methods: {
			save(){
				if(!/^\d+$/.test(this.pid)){
					uni.showToast({icon:'none',title:'上级ID有误'});
					return;
				}
				let uidarr=this.uid.split(',');
				if(uidarr.length<1){
					uni.showToast({icon:'none',title:'下级ID列表有误'});
					return;
				}
				for (let item of uidarr) {
					if(!/^\d+$/.test(item)){
						uni.showToast({icon:'none',title:'下级ID:'+item+' 有误'});
						return;
					}
				}
				const pid=this.pid,uid=uidarr.join(',');
				this.comm.http('/api/tool/setpid',{pid,uid}).then(res=>{
					uni.showToast({icon:'none',title:res.msg});
				});
			}
		}
	}
</script>

<style lang="scss">
	.setpidpage{
		.inputitem{
			align-items: center;
			view:nth-child(2){
				flex: 1;margin-left: 8px;
				input{
					height:40px; width: 100%; border-bottom: 1px solid #f0f0f0; font-size: 13px;
				
				}
			}

		}
		.tips{
			font-size: 12px; color: #999; padding: 8px 0; display: block;
		}
	}
</style>
